const { Sequelize } = require("sequelize");
const CreateDB = require("../Model");
const {
  MYSQL_HOST,
  MYSQL_PORT,
  MYSQL_USER,
  MYSQL_PWD,
  MYSQL_DB,
} = require("../Config/config.default");
// 创建 Sequelize 实例，连接到默认数据库
const seq = new Sequelize(`mysql://${MYSQL_USER}:${MYSQL_PWD}@localhost:3306`);
seq.query(`CREATE DATABASE IF NOT EXISTS ${MYSQL_DB};`).then(() => {
  const newSel = new Sequelize(MYSQL_DB, MYSQL_USER, MYSQL_PWD, {
    host: MYSQL_HOST,
    dialect: "mysql",
  });

  newSel
    .authenticate()
    .then(() => {
      console.log("连接成功");
      CreateDB();
    })
    .catch((err) => {
      console.log("数据库连接失败", err);
    });
});
